<?php

declare(strict_types=1);
/**
 * This file is part of bearing-web.
 *
 * @link     https://www.bearing.cn/
 * @contact  tech@bearing.cn
 * @license  https://gitee.com/cppo/bearing_web/-/blob/master/README.md
 */

namespace frontend\actions;

use yii\base\InvalidConfigException;
use yii\db\ActiveRecord;
use yii\db\ActiveRecordInterface;
use yii\helpers\ArrayHelper;
use yii\rest\CreateAction;
use yii\web\ServerErrorHttpException;

class MessageCreateAction extends CreateAction
{
    /**
     * @throws InvalidConfigException|ServerErrorHttpException
     */
    public function run(): ActiveRecord|ActiveRecordInterface
    {
        \Yii::$app->getRequest()->setBodyParams(ArrayHelper::merge(
            \Yii::$app->getRequest()->getBodyParams(),
            [
                'user_id' => intval(\Yii::$app->user->identity->getId()),
            ]
        ));
        return parent::run();
    }
}
